﻿using Lsk.Business;
using Lsk.Business.DTO;
using Lsk.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace lsk.Web.Api
{
    public class PropertySearchController : ApiController
    {
        [HttpPost]
        public HttpResponseMessage GetSaleProperty(dynamic data)
        {
            // @SaleType='SR' => S = Sale , R = Residential, C = Commercial, L = Land, I = Industrial
            // @SaleType='RR' => R = Rent , R = Residential, C = Commercial, L = Land, I = Industrial
            PropertySearchParameter entry = JsonConvert.DeserializeObject<PropertySearchParameter>(data.ToString());
            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetSaleProperty_Result> results=  srchMgr.GetSaleProperty(entry);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }

        [HttpPost]
        public HttpResponseMessage GetRentProperty(dynamic data)
        {
            PropertySearchParameter entry = JsonConvert.DeserializeObject<PropertySearchParameter>(data.ToString());
            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetRentProperty_Result> results = srchMgr.GetRentProperty(entry);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }

        [HttpPost]
        public HttpResponseMessage GetBestBuytProperty()
        {
            
            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetBestBuyAllSaleProperty_Result> results = srchMgr.GetBestBuyProperty();
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }

        [HttpGet]
        public IEnumerable<GetSalePropertyByAgent_Result> GetSalePropertyByAgentName(string agentName)
        {

            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetSalePropertyByAgent_Result> results = srchMgr.GetSalePropertiesByAgent(agentName);
            return results;
        }

        [HttpPost]
        public IEnumerable<GetAllNewSaleProperty_Result> GetAllNewSaleProperty()
        {

            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetAllNewSaleProperty_Result> results = srchMgr.GetAllNewSaleProperty();
            return results;
        }

        [HttpPost]
        public IEnumerable<GetAllNewRentProperty_Result> GetAllNewRentProperty()
        {

            PropertySearch srchMgr = new PropertySearch();
            IEnumerable<GetAllNewRentProperty_Result> results = srchMgr.GetAllNewRentProperty();
            return results;
        }
    }
}
